﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using WebDS;
using WebUS;
using WebDS.CDBNames;
using IP.Core.IPCommon;
using System.Data;
using IP.Core.IPData.DBNames;
using IP.Core.IPUserService;
using IP.Core.IPData;

public partial class ChucNang_Ban_giao_thiet_bi : System.Web.UI.Page
{
    #region bienToanCuc
    US_GD_BAO_TRI_LINH_KIEN_THAY_THE m_us_gd_bao_tri_linh_kien_thay_the = new US_GD_BAO_TRI_LINH_KIEN_THAY_THE();
    DS_GD_BAO_TRI_LINH_KIEN_THAY_THE m_ds_gd_bao_tri_lin_kien_thay_the = new DS_GD_BAO_TRI_LINH_KIEN_THAY_THE();
    int m_id_bao_tri_thiet_bi;
    #endregion

    protected void Page_Load(object sender, EventArgs e)
    {
        m_id_bao_tri_thiet_bi = Convert.ToInt32(Request.Cookies["Id"].Value);
        if (!IsPostBack)
        {
            loadDataGridViewLinhKien();
            LoadCBOLinhKien();
        }
    }

    protected void loadDataGridViewLinhKien()
    {
        US_GD_BAO_TRI_LINH_KIEN_THAY_THE v_us_gd_bao_tri_linh_kien_thay_the = new US_GD_BAO_TRI_LINH_KIEN_THAY_THE();
        DS_GD_BAO_TRI_LINH_KIEN_THAY_THE v_ds_gd_bao_tri_linh_kien_thay_the = new DS_GD_BAO_TRI_LINH_KIEN_THAY_THE();
        v_us_gd_bao_tri_linh_kien_thay_the.filldataset_gd_bao_tri_linh_kien_id_dot_bao_tri(m_id_bao_tri_thiet_bi, v_ds_gd_bao_tri_linh_kien_thay_the);
        m_grv_dm_linh_kien.DataSource = v_ds_gd_bao_tri_linh_kien_thay_the;
        m_grv_dm_linh_kien.DataBind();
    }

    protected void LoadCBOLinhKien()
    {
        try
        {
            US_CM_DM_TU_DIEN v_us_dm_tu_dien = new US_CM_DM_TU_DIEN();
            DS_CM_DM_TU_DIEN v_ds_dm_tu_dien = new DS_CM_DM_TU_DIEN();
            v_us_dm_tu_dien.FillDataset(v_ds_dm_tu_dien, " WHERE ID_LOAI_TU_DIEN = 2");
            m_cbo_linh_kien.DataSource = v_ds_dm_tu_dien.CM_DM_TU_DIEN;
            m_cbo_linh_kien.DataTextField = CM_DM_TU_DIEN.TEN;
            m_cbo_linh_kien.DataValueField = DM_DIA_PHUONG_BENH_VIEN.ID;
            m_cbo_linh_kien.DataBind();
        }
        catch (Exception v_e)
        {

            CSystemLog_301.ExceptionHandle(this, v_e);
        }
        
    }

    protected void xoa_form()
    {
        m_txt_sn_cu.Text = "";
        m_txt_sn_moi.Text = "";
    }

    protected void form_2_us_object()
    {
        m_us_gd_bao_tri_linh_kien_thay_the.dcID_DOT_BAO_TRI = m_id_bao_tri_thiet_bi;
        m_us_gd_bao_tri_linh_kien_thay_the.dcID_LINH_KIEN = Convert.ToInt32(m_cbo_linh_kien.SelectedValue);
        m_us_gd_bao_tri_linh_kien_thay_the.strSN_CU = m_txt_sn_cu.Text;
        m_us_gd_bao_tri_linh_kien_thay_the.strSN_MOI = m_txt_sn_moi.Text;
    }


    protected void m_btn_them_linh_kien_moi_Click(object sender, EventArgs e)
    {
        try
        {
            m_us_gd_bao_tri_linh_kien_thay_the.Insert();
            loadDataGridViewLinhKien();
            xoa_form();
        }
        catch (Exception v_e)
        {            
            CSystemLog_301.ExceptionHandle(this, v_e);
        }
    }
    protected void m_btn_tiep_tuc_Click(object sender, EventArgs e)
    {
        Response.Cookies["Id"].Value = m_id_bao_tri_thiet_bi.ToString();
        Response.Redirect("~/ChucNang/BaoTriThietBi/Noi_dung_bao_duong.aspx");
    }
}